﻿using UnityEngine;
using System.Collections;

public class CellScale : MonoBehaviour {

	public Transform tweenTarget;
	public Vector3 pressed = new Vector3(1.05f, 1.05f, 1.05f);
	public float duration = 0.2f;
	
	Vector3 mScale;
	bool mStarted = false;
	
	void Start ()
	{
		if (!mStarted)
		{
			mStarted = true;
			if (tweenTarget == null) tweenTarget = transform;
			mScale = tweenTarget.localScale;
		}
	}
	
	void OnDisable ()
	{
		if (mStarted && tweenTarget != null)
		{
			TweenScale tc = tweenTarget.GetComponent<TweenScale>();
			
			if (tc != null)
			{
				tc.value = mScale;
				tc.enabled = false;
			}
		}
	}
	
	void OnPress (bool isPressed)
	{
		if (enabled)
		{
			if (!mStarted) Start();
			TweenScale.Begin(tweenTarget.gameObject, duration, isPressed ? Vector3.Scale(mScale, pressed) :
			                 mScale).method = UITweener.Method.EaseInOut;          
		}
	}


}
